package com.qys.livesMall.shop.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qys.livesMall.app.user.model.dto.sys.SysHomeStatisticsDTO;
import com.qys.livesMall.finance.enums.AccountBusinessTypeEnum;
import com.qys.livesMall.shop.constants.ShopConstant;
import com.qys.livesMall.shop.dao.H2ShopRechargeWithdrawalDao;
import com.qys.livesMall.shop.mapper.H2ShopRechargeWithdrawalMapper;
import com.qys.livesMall.shop.modal.entity.H2ShopRechargeWithdrawal;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 店铺充值提现表 服务实现类
 * </p>
 *
 * @author
 * @since 2023-06-06
 */
@Service
public class H2ShopRechargeWithdrawalDaoImpl extends ServiceImpl<H2ShopRechargeWithdrawalMapper, H2ShopRechargeWithdrawal> implements H2ShopRechargeWithdrawalDao {

    @Override
    public BigDecimal getAuditWithdrawal(SysHomeStatisticsDTO dto) {
        return baseMapper.getAuditWithdrawal(dto);
    }

    @Override
    public BigDecimal getInitiateWithdrawal(Integer userSysType) {
        return baseMapper.getInitiateWithdrawal(userSysType);
    }

    public H2ShopRechargeWithdrawal getWaitAuditWl(Long userId){
        LambdaQueryWrapper<H2ShopRechargeWithdrawal> qw=new LambdaQueryWrapper<>();
        qw.eq(H2ShopRechargeWithdrawal::getType, AccountBusinessTypeEnum.SHOP_WITHDRAWAL.getType());
        qw.eq(H2ShopRechargeWithdrawal::getUserId,userId);
        qw.eq(H2ShopRechargeWithdrawal::getStatus, ShopConstant.RWStatus.WAIT_AUDIT);
        qw.last("limit 1");
        return getOne(qw);
    }

    @Override
    public boolean isFirstRecharge(Long shopId) {
        LambdaQueryWrapper<H2ShopRechargeWithdrawal> qw=new LambdaQueryWrapper<>();
        qw.eq(H2ShopRechargeWithdrawal::getType, AccountBusinessTypeEnum.SHOP_RECHARGE.getType());
        qw.eq(H2ShopRechargeWithdrawal::getShopId,shopId);
        qw.eq(H2ShopRechargeWithdrawal::getStatus, ShopConstant.RWStatus.AUDITED);
        qw.last("limit 1");
        return getOne(qw)!=null?false:true;
    }
}
